package com.netease.nimlib.fts.query;

import java.util.regex.Pattern;

import android.text.TextUtils;

public final class FTSQuery {

	private static final Pattern QUERY_PATTERN = Pattern.compile("\\s+");

	public static final String queryString(String query) {
		if (query != null) {
			query = query.trim();
		}

		String[] querys = !TextUtils.isEmpty(query) ? QUERY_PATTERN.split(query
				.replace('*', ' ')) : null;
		if (querys == null || querys.length == 0) {
			return "";
		}

		StringBuilder sb = new StringBuilder(32);
		for (String q : querys) {
			if (!TextUtils.isEmpty(query)) {
				sb.append('"');
				sb.append(q);
				sb.append("*\" ");
			}
		}

		return sb.toString();
	}
}
